package com.springcloud_provider.controller;

import com.springcloud_api.entity.StudentPO;
import com.springcloud_provider.service.impl.StudentServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: Wu Linchun
 * @date: 2021/09/16/15:10
 * @Description:
 **/

@EnableAutoConfiguration
@Controller
@RequestMapping("/index")
public class MyController {
    @Autowired
    private StudentServiceImpl studentService;

    @GetMapping(value = {"/testInsert"})
    @ResponseBody
    public String testInsert() {
        StudentPO student = new StudentPO(20160001, "zhangsan", 20, "M", "2016222");
        System.out.println(student.toString());
        return String.valueOf(studentService.insertStudent(student));
    }

    @GetMapping("/getStudent")
    @ResponseBody
    public StudentPO getStudentBySno(@RequestParam("sno") String sno) {
        System.out.println(studentService.getBySno(Integer.parseInt(sno)));
        return studentService.getBySno(Integer.parseInt(sno));
    }

    @PostMapping("/saveStudent")
    @ResponseBody
    public String saveStudent(@RequestBody StudentPO student) {
        studentService.insertStudent(student);
        return "保持成功";
    }

    @GetMapping("/getAll")
    @ResponseBody
    public List<StudentPO> getAll() {
        return studentService.getAll();
    }

    @GetMapping("/testGroup")
    @ResponseBody
    public String testGroup() {
        return "springcloud-provider-8082";
    }


}
